/* eslint-disable eqeqeq */
import actionInfo from '../action'
import { productcolorAdd, productcolorQuery } from '../service/productcolorService'

function productcolorInfoReducer(state = { productcolorList: [] }, action) {
    switch (action.type) {
        case actionInfo.productcolor.ADD:
            return { productcolorList: [...state.productcolorList, action.payload] }
        case actionInfo.productcolor.QUERY:
            return { productcolorList: action.payload }
        default:
            return state
    }
}
export const asyncProductcolorQuery = (params) => async (dispatch) => {
    let { data } = await productcolorQuery(params);//做异步请求
    dispatch(productcolorInfoQuery(data.msg));//
}
const productcolorInfoQuery = (payload) => {
    return {
        type: actionInfo.productcolor.QUERY,
        payload
    }
}
export const asyncProductcolorAdd = (params) => async (dispatch) => {
    let { data } = await productcolorAdd(params);//做异步请求
    console.log(data.msg);
    if (data.code == 1) {
        dispatch(productcolorInfoAdd(...data.msg));
    }
}
const productcolorInfoAdd = (payload) => {
    return {
        type: actionInfo.productcolor.ADD,
        payload
    }
}
export default productcolorInfoReducer